/*
 * Copyright 2008-2023 dexian.vip. All rights reserved.
 * Support: http://www.dexian.vip
 * License: http://www.dexian.vip/license
 */

package vip.dexian.admin.config;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 错误页面配置。请注意一定要配置servlet.encoding，否则中文会出现乱码。具体可查看 {@link org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration}、{@link org.springframework.boot.web.servlet.support.ErrorPageFilter}
 *
 * @author 挺好的 2023年05月30日 17:18
 */
@Component
public class ErrorPagesConfig implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages (ErrorPageRegistry registry) {

        ErrorPage error400 = new ErrorPage(HttpStatus.BAD_REQUEST, "/error/400");
        ErrorPage error401 = new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401");
        ErrorPage error403 = new ErrorPage(HttpStatus.FORBIDDEN, "/error/403");
        ErrorPage error404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
        ErrorPage error405 = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/error/405");
        ErrorPage error409 = new ErrorPage(HttpStatus.CONFLICT, "/error/409");
        ErrorPage error422 = new ErrorPage(HttpStatus.UNPROCESSABLE_ENTITY, "/error/422");
        ErrorPage error423 = new ErrorPage(HttpStatus.LOCKED, "/error/423");
        ErrorPage error500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
        ErrorPage errorThrowable = new ErrorPage(Throwable.class, "/error/500");

        registry.addErrorPages(error400, error401, error403, error404, error405, error409, error422, error423, error500,
                errorThrowable
        );

    }
}
